package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags="护理计划")
public class NursingPlanController extends BaseController{

    @Autowired
    NursingPlanService nursingPlanService;
    @ApiOperation("查询所有")
    @GetMapping
    public ResponseResult<List<NursingPlanVo>> getAll(){
       List<NursingPlanVo> nursingPlanVoList= nursingPlanService.getAllPlan();
       return success(nursingPlanVoList);
    }

    @ApiOperation("新增数据")
    @PostMapping
    public ResponseResult addPlan(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.addPlan(nursingPlanDto);
        return success();
    }

    @ApiOperation("条件分页查询")
    @GetMapping("/search")
    public ResponseResult<PageResponse<NursingPlanVo>> pageQuery(
            @ApiParam("护理计划名字")
            String name,
            @ApiParam("页码")
            Integer pageNum,
            @ApiParam("每页大小")
            Integer pageSize,
            @ApiParam("护理计划状态")
            Integer status

    ){
        PageResponse<NursingPlanVo> nursingPlanPage= nursingPlanService.pageQuery(name,pageNum,pageSize,status);
        return success(nursingPlanPage);
    }


    @ApiOperation(value="根据id查询",notes = "查询出计划及其所有包含的项目")
    @GetMapping("/{id}")
    public ResponseResult<NursingPlanVo> getById(@PathVariable("id")Integer id){
        NursingPlanVo nursingPlanVo =nursingPlanService.getByPlanId(id);
        return success(nursingPlanVo);
    }

    @ApiOperation("编辑护理计划")
    @PutMapping("/{id}")
    public ResponseResult update(@RequestBody NursingPlanDto nursingPlanDto){
       nursingPlanService.updateNursingPlan(nursingPlanDto);
        return success();
    }

    @ApiOperation("删除护理计划")
    @DeleteMapping("/{id}")
    public ResponseResult DeleteNursingPlan(@PathVariable("id") Integer id){
        nursingPlanService.deleteBursingPlan(id);
        return success();
    }

    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult setStatus(
            @PathVariable("id") Integer id,
            @PathVariable("status") Integer status

    ){
        nursingPlanService.setStatus(id,status);
        return success();
    }

}
